home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / ENV Server / client src / client.c
Encoding:
C/C++ Source or Header  |  1993-05-31  |  2.4 KB  |  129 lines  |  [TEXT/ALFA]

  1. /*
  2. ** client.c
  3. ** 
  4. ** Sample application using the EnvironServer for environment
  5. ** variables.
  6. **
  7. ** To be 100% correct, the #include <MacHeaders> and calls to DisposPtr()
  8. ** are necessary.  Otherwise, if you aren't worried about a few stray
  9. ** pointer blocks and a possibly fragmented heap, don't worry...
  10. **
  11. ** This code if freely distributable and modifiable as long as I am
  12. ** mentioned in any derived works.  This code is Copyright (C) 1993 by
  13. ** Brent Burton.
  14. **
  15. ** Brent Burton
  16. ** brentb@tamsun.tamu.edu
  17. **
  18. ** 5/12/93 - created
  19. ** 5/29/93 - my birthday ;-)
  20. ** 5/31/93 - cleaned up the code, comments
  21. */
  22.  
  23. #define PEDANTIC 1      /* define to be 1 if you want 100% correctness */
  24.  
  25. #if PEDANTIC
  26. #  include <MacHeaders>
  27. #endif
  28.  
  29. #include <stdio.h>
  30. #include "GetPutEnv.h"
  31.  
  32. void print_vars(void);
  33.  
  34. main()
  35. {
  36.     char s[20];
  37.     int d1, d2, d3, d4, d5;
  38.  
  39.     printf("Standard UNIX program processing here....\n\n");
  40.     printf("Press return\n\n");
  41.     fgets(s, 10, stdin);
  42.     printf("Initial values for environment vars are:\n");
  43.     
  44.     print_vars();
  45.  
  46.     printf("\nBeginning insertions...(expect all 0's now)\n");
  47.     d1 = putenv("TERM=new_TERM_value");
  48.     d2 = putenv("LANG=new_LANG_value");
  49.     d3 = putenv("HOME=new_HOME_value");
  50.     d4 = putenv("SHELL=new_SHELL_value");
  51.     d5 = putenv("ORGANIZATION=Texas A&M University");
  52.     printf("Return codes are:  %d  %d  %d  %d  %d\n", d1, d2, d3, d4, d5);
  53.     printf("Done inserting...\n");
  54.  
  55.     printf("\nNew environment variable values are:\n");
  56.     
  57.     print_vars();
  58.     printf("Done.\n");
  59. }
  60.  
  61.  
  62. /*
  63. ** print_vars
  64. **
  65. ** print out the 5 environment variables I am testing.
  66. */
  67. void
  68. print_vars(void)
  69. {
  70. #if PEDANTIC
  71.     Ptr s1, s2, s3, s4, s5;
  72. #else
  73.     char *s1, *s2, *s3, *s4, *s5;
  74. #endif
  75.  
  76.     if ( (s1 = getenv("TERM")) == NULL)
  77.         printf("s1(TERM) null.\n");
  78.     else
  79.     {
  80.         printf("s1(TERM) = >%s<\n", s1);
  81. #if PEDANTIC
  82.         DisposPtr( s1);
  83. #endif
  84.     }
  85.  
  86.     
  87.     if ( (s2 = getenv("LANG")) == NULL)
  88.         printf("s2(LANG) null.\n");
  89.     else
  90.     {
  91.         printf("s2(LANG) = >%s<\n", s2);
  92. #if PEDANTIC
  93.         DisposPtr( s2);
  94. #endif
  95.     }
  96.  
  97.  
  98.     if ( (s3 = getenv("HOME")) == NULL)
  99.         printf("s3(HOME) null.\n");
  100.     else
  101.     {
  102.         printf("s3(HOME) = >%s<\n", s3);
  103. #if PEDANTIC
  104.         DisposPtr( s3);
  105. #endif
  106.     }
  107.  
  108.  
  109.     if ( (s4 = getenv("SHELL")) == NULL)
  110.         printf("s4(SHELL) null.\n");
  111.     else
  112.     {
  113.         printf("s4(SHELL) = >%s<\n", s4);
  114. #if PEDANTIC
  115.         DisposPtr( s4);
  116. #endif
  117.     }
  118.  
  119.  
  120.     if ( (s5 = getenv("ORGANIZATION")) == NULL)
  121.         printf("s5(ORGANIZATION) null.\n");
  122.     else
  123.     {
  124.         printf("s5(ORGANIZATION) = >%s<\n", s5);
  125. #if PEDANTIC
  126.         DisposPtr( s5);
  127. #endif
  128.     }
  129. }